<?php

$sql = 'SELECT id,region_id,cp FROM '.PWE::getPrefixBdd().'ville WHERE region_id IS NULL LIMIT 100';
$result = bdd_sql::doSql($sql, true);
$continue = true;

if($result['count']>0){
    foreach($result['results'] as $datas){
        $region = modele_region::getRegionByDept($datas['cp']);
        if($region!==null && $region->getId()>0){
            $sql = 'UPDATE '.PWE::getPrefixBdd().'ville SET region_id='.$region->getId().' WHERE id='.$datas['id'];
            bdd_sql::doSql($sql,false);
            echo '- Ville '.$datas['id'].' à jour : region '.$region->getId().'<br/>';
        }
    }
    echo 'traitement en cours';
    echo '<script>'
    . 'setTimeout("window.location.reload()",2000);'
    . '</script>';
}else{
    echo 'traitement fini';
}
?>